package org.ssssssss.magicapi.utils;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.ftp.Ftp;
import cn.hutool.extra.ftp.FtpMode;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;

@Component
public class MyFTPUtils {

    public void testFtp() {
        String ftp_server = "172.18.65.108";
        int ftp_port = 21;
        String ftp_file_path = "/home/amax/repository/xj/006750.jpg";
        String ftp_user_name = "amax";
        String ftp_password = "amax1979!";
        //ThreadUtil.sleep(1000);

        String fileName = FileUtil.getName(ftp_file_path);
        final String dir = StrUtil.removeSuffix(ftp_file_path, fileName);

        Ftp ftp = null;
        try{
            ftp = new Ftp(ftp_server, ftp_port, ftp_user_name, ftp_password);
            ftp.setMode(FtpMode.Passive);
            System.out.println(ftp);
            //下载远程文件
            ftp.download(dir, fileName, FileUtil.file("D://aa.txt"));
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                assert ftp != null;
                ftp.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public void testData(){

        String ftp_file_path = "C://my/down.txt";
        String fileName = FileUtil.getName(ftp_file_path);
        final String dir = StrUtil.removeSuffix(ftp_file_path, fileName);

        System.out.println(dir+":"+fileName);
    }
}
